const app = getApp();

Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    isPopup: false,
    smallWindow: false,
    urlNote: "",
    popupUrl: "",
    pictureList: [],
    pictureNum: 0,
    pictureTotal: 0,
    picture: "",
    nextLoc: '',
    skipLoc: '',
    skipHeight: 0,
    skipWidth: 0,
    skipRight: 0,
    knowRight: 0,
    nextTop: 0,
  },

  lifetimes: {
    attached() {
      var token = wx.getStorageSync('usertoken');

      if (app.globalData.personalList.length > 0 && token) {
        if (app.globalData.personalList[0].popupMode == 'full') {
          app.globalData.tabbarHeight = 0
          wx.hideTabBar()
          this.setData({
            isPopup: true
          })
        } else {
          this.setData({
            smallWindow: true,
            urlNote: app.globalData.personalList[0].urlNote,
            popupUrl: app.globalData.personalList[0].url
          })
        }
        let knowRight = 0
        let left = 0
        let capsule = wx.getMenuButtonBoundingClientRect()
        let skipRight = capsule.left
        let skipWidth = capsule.width
        left = skipRight + skipWidth
        knowRight = 750 - left * (750 / wx.getSystemInfoSync().windowWidth)
        this.setData({
          pictureList: app.globalData.personalList,
          pictureTotal: app.globalData.personalList.length,
          picture: app.globalData.personalList[0].templatePath,
          skipLoc: app.globalData.personalList[0].skipLoc,
          nextLoc: app.globalData.personalList[0].nextLoc,
          skipHeight: app.globalData.navigationBar - 4 + 'px',
          skipWidth: capsule.width - 4 + 'px',
          skipRight: capsule.left,
          knowRight: knowRight,
          nextTop: capsule.top + 'px'
        })
      }
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    insertLog() {
      let that = this
      let openId = wx.getStorageSync('openid')
      var userid = wx.getStorageSync('userid');
      var phoneNumber = wx.getStorageSync('phoneNumber');
      app.reqZS({
        url: '/popup/insertLog',
        method: 'post',
        header: {},
        data: {
          openId: openId,
          popupId: app.globalData.personalList[0].popupId,
          userId: userid,
          phoneNumber: phoneNumber,
          loginStatus: that.data.loginStatus,
          pageName: 'personal'
        },
        success: function (res) {
          if (res.data.code == 10000) {}
        }
      })
    },
    tiaoguo(num, isSensor) {
      this.sensorPopup('跳过')
      this.insertLog()
      wx.showTabBar()
      this.setData({
        isPopup: false
      })
    },
    next() {
      this.sensorPopup('知道了')
      if (this.data.pictureNum < this.data.pictureTotal - 1) {
        this.data.pictureNum++
        this.setData({
          picture: this.data.pictureList[this.data.pictureNum].templatePath,
          pictureNum: this.data.pictureNum,
          nextLoc: this.data.pictureList[this.data.pictureNum].nextLoc,
          skipLoc: this.data.pictureList[this.data.pictureNum].skipLoc,
          urlNote: app.globalData.personalList[this.data.pictureNum].urlNote,
          popupUrl: app.globalData.personalList[this.data.pictureNum].url
        })
      } else {
        this.insertLog()
        wx.showTabBar()
        this.setData({
          isPopup: false
        })
      }
    },
    btnPopup() {
      const src = this.data.popupUrl
      this.sensorPopup(this.data.urlNote)
      this.insertLog()
      this.setData({
        smallWindow: false
      })
      if (this.data.popupUrl.indexOf('http') > -1) {
        wx.navigateTo({
          url: '/pages/topicDetail/index?src=' + encodeURIComponent(src),
        })
      } else {
        wx.navigateTo({
          url: src,
        })
      }
  
    },
    onCloseyouq() {
      this.insertLog()
      this.setData({
        smallWindow: false
      })
    },
    /**
     * popup--神策埋点
     * @param {*} typeName 
     */
    sensorPopup(typeName) {
      console.log("************popup--")
      let remark = app.globalData.personalList[this.data.pictureNum].remark
      let pageName = remark ? 'popup-我的-' + remark : 'popup-我的'
      getApp().sensors.track('MP_CommonOperate_BtnClick', {
        type: typeName, //类型
        content_type: 'popup', //内容类型 
        page_name: pageName, //页面名称
        info_source: '', //来源--金十
        article_id: '', //文章id
        article_title: '', //文章标题
        article_type_list: [], //文章类型列表
        analyst_list: [], //研究员列表
        meeting_id: '', //会议id
        meeting_name: '', //会议名称
        analyst_name: '', //研究员名称
        inviter_code: '',
        report_type: '', //报告类型
        futures_category: '', //期货类别
        futures_variety: [] //期货品种
  
      });
    }
  }
})